package colors;

public class Color 
{
	public float A;
	public float R;
	public float G;
	public float B;
	
	public Color(float r, float g, float b, float a)
	{
		this.R = r;
		this.G = g;
		this.B = b;
		this.A = a;
	}
	
	public Color(float r, float g, float b)
	{
		this.R = r;
		this.G = g;
		this.B = b;
		this.A = 1;		
	}
	
	public Color(int r, int g, int b, int a)
	{
		this.R = r / 255.0f;
		this.G = g / 255.0f;
		this.B = b / 255.0f;
		this.A = a / 255.0f;
	}
	
	public Color(int r, int g, int b)
	{
		this.R = r / 255.0f;
		this.G = g / 255.0f;
		this.B = b / 255.0f;
		this.A = 1.0f;
	}
	
	@Override
	public boolean equals(Object o)
	{
		if(this.R != ((Color)o).R)
		{
			return false;
		}		
		if(this.G != ((Color)o).G)
		{
			return false;
		}
		if(this.B != ((Color)o).B)
		{
			return false;
		}		
		if(this.A != ((Color)o).A)
		{
			return false;
		}
		return true;
	}
	
	public int toId()
	{
		return (int) (R * 255 * 255 * 255 + G * 255 * 255 + B * 255); 
	}
	
	public float[] toFloatArray()
	{
		return new float[] {this.R, this.G, this.B, this.A };
	}
	
	public static Color FromInt(int i)
	{
		return new Color( (int)(i / (65025)), (int)(i / 255) , (int)(i % 255) );
	}
	
	public String toString()
	{
		return "r = " + R +" ; g = " + G +" ; b = " + B + "; A = " + A ;
	}
}
